package org.example;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

public class IMUserProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("im_producer_group");
        producer.setNamesrvAddr("124.71.28.51:9876");
        // 设置消息发送超时时间，默认为3秒
        producer.start();

        // 发送消息给用户A
        sendMessage("UserA", "Hello from UserB", producer);

        producer.shutdown();
    }

    private static void sendMessage(String user, String content, DefaultMQProducer producer) throws Exception {
        Message message = new Message("IM_TOPIC_HZA", "TAG_HZA", (user + ":" + content).getBytes());
        producer.send(message);
        System.out.println("Message sent: " + content);
    }
}
